package com.example.entity;

import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

@Data
public class Order {
    int id;
    int userId;
    String user_name;
    int flightNo;
    String airline;
    String date;//创建日期
    String from;
    String to;
    String departure;
    String arrival;
    double price;
    int passengers;
    String status;  //unpaid、paid、completed、cancelled、refund
    String statusText;  //待支付、已支付、已完成、已取消、退款中
    String paymentMethod;
    String paymentDate;
    String paymentDeadline;
    String cancelDate;
    String refundDate;

    public String getOrder_id() {
        try {
            // 将字符串解析为 Date 对象
            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date dateObj = inputFormat.parse(this.date);

            // 只提取日期部分
            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd");
            String formattedDate = outputFormat.format(dateObj);

            return "HLTH" + formattedDate + "-" + String.format("%04d", id);
        } catch (Exception e) {
            throw new RuntimeException("日期格式转换失败: " + this.date, e);
        }
    }

    public String getFlight_id() {
        if (Objects.equals(airline, "南方航空公司")){
            return "CZ" + String.format("%05d", flightNo);
        }else if(Objects.equals(airline, "东方航空公司")){
            return "MU" + String.format("%05d", flightNo);
        } else if (Objects.equals(airline, "中国国际航空公司")) {
            return "CA" + String.format("%05d", flightNo);
        } else{
            return "N/A";
        }
    }
}
